CREATE OR REPLACE PROCEDURE sp_drop_city_id_name_index() LANGUAGE plpgsql AS $$
DECLARE index_name varchar(255);
BEGIN
    SELECT MAX(indexname) FROM pg_indexes WHERE tablename = 'companies' AND indexdef ILIKE '% unique %'
		    AND indexdef ILIKE '%(city_id, name)%' INTO index_name;
    RAISE NOTICE '索引名称: %', index_name;
		IF index_name IS NOT NULL THEN
		    EXECUTE 'DROP INDEX ' || index_name;
		END IF;
END;
$$;

CALL sp_drop_city_id_name_index();

DROP PROCEDURE sp_drop_city_id_name_index;

CREATE INDEX ON "companies"("city_id", "name");
